---
title: Working with iframes
---

### What is an iframe?

Iframes embed other pages within your current page. Sites use them for consent banners, payment widgets, chat bubbles, and third-party content.
Elements inside iframes exist in a separate context than the main page.

### Enable iframe support

Set `iframes: true` in your `act()`, `observe()`, and `extract()` commands.

<CodeGroup>
```typescript TypeScript
// Act within iframes
await page.act({ action: "click the accept cookies button", iframes: true });

// Observe within iframes
const results = await page.observe({
  instruction: "Find the primary action button",
  iframes: true,
});

// Extract from iframes
const data = await page.extract({
  instruction: "Extract the product price from the payment widget",
  schema: z.object({
    price: z.string(),
  }),
  iframes: true,
});
```

```python Python
# Act within iframes
await page.act(
    "click the accept cookies button",
    iframes=True
)

# Observe within iframes
results = await page.observe({
    "instruction": "Find the primary action button",
    "iframes": True,
})

# Extract from iframes
data = await page.extract({
    "instruction": "Extract the product price from the payment widget",
    "schema": {
        "type": "object",
        "properties": {
            "price": {"type": "string"}
        }
    },
    "iframes": True,
})
```
</CodeGroup>

### Tips

- Iframes can increase processing time. For best performance, use the iframe option only when necessary.
- When you are unsure whether an element will be in an iframe, you can verify the presence of iframes in Stagehand logs.
- If an element intermittently fails to be found, it may be inside a lazy‑loaded iframe. Add small waits between steps or re‑run your action.

<Note>
You can enable experimental features (like Shadow DOM support) via your Stagehand configuration. See the [configuration guide](/configuration/browser).
</Note>

## Next steps

<CardGroup cols={2}>
  <Card title="Analyze pages with observe()" icon="magnifying-glass" iconType="sharp-solid" href="/basics/observe">
    Use `observe()` to plan precise, single-step actions before executing them.
  </Card>

  <Card title="Extract data with extract()" icon="table" iconType="sharp-solid" href="/basics/extract">
    Use `extract()` with a data schema to pull clean, typed data from any page.
  </Card>

  <Card title="Caching actions" icon="bolt" iconType="sharp-solid" href="/best-practices/caching">
    Speed up repeated automations by caching actions.
  </Card>

  <Card title="Act fundamentals" icon="arrow-pointer" iconType="sharp-solid" href="/basics/act">
    Learn how to perform single-step actions reliably with `act()`.
  </Card>
</CardGroup>